// Color.h
//
#ifndef COLOR_ONCE
#define COLOR_ONCE

#include "Framework_Exports.h"

namespace OpenGL {

class FWK_API Color
{
private:
	float _r,_g,_b,_a;

public:
	// ------------------------------------------------------------------------------------------------
	Color() : _r(.5f),_g(.5f),_b(.5f),_a(1.f)	{}

	// ------------------------------------------------------------------------------------------------
	explicit Color(unsigned char R, unsigned char G, unsigned char B, unsigned char A = 255) : _r(R/255.f),_g(G/255.f),_b(B/255.f),_a(A/255.f)	{}

	// ------------------------------------------------------------------------------------------------
	Color(float R, float G, float B, float A = 1.f) : _r(R),_g(G),_b(B),_a(A)	{}
	
	// ------------------------------------------------------------------------------------------------
	float r() const { return _r; }
	float g() const { return _g; }
	float b() const { return _b; }
	float a() const { return _a; }
	float *rgba()   { return &_r;}
	float luminance() const { return (_r*0.2126f)+(_g*0.7152f)+(_b*0.0722f); }
	bool equals( const Color &other ) const { return _r==other._r && _g==other._g && _b==other._b && _a==other._a; }
	
	// ------------------------------------------------------------------------------------------------
	Color lighter( float b = 0.5f ) const 
	{ 
		const float br = _r+b > 1.0f ? 1.0f : _r+b;
		const float bg = _g+b > 1.0f ? 1.0f : _g+b;
		const float bb = _b+b > 1.0f ? 1.0f : _b+b;

		return Color(br,bg,bb,_a);
	}

	// ------------------------------------------------------------------------------------------------
	Color darker( float b = 0.5f ) const 
	{ 
		const float br = _r-b < 0.0f ? 0.0f : _r-b;
		const float bg = _g-b < 0.0f ? 0.0f : _g-b;
		const float bb = _b-b < 0.0f ? 0.0f : _b-b;

		return Color(br,bg,bb,_a);
	}

	// ------------------------------------------------------------------------------------------------
	Color transparent( float alpha = 0.5f ) const 
	{ 
		return Color(_r,_g,_b,_a*alpha);
	}

	// ------------------------------------------------------------------------------------------------
	// Colors by name
	static Color white()  { return Color(1.f,1.f,1.f,1.f); }
	static Color black()  { return Color(0.f,0.f,0.f,1.f); }
	static Color red()	  { return Color(1.f,0.f,0.f,1.f); }
	static Color green()  { return Color(0.f,1.f,0.f,1.f); }
	static Color blue()   { return Color(0.f,0.f,1.f,1.f); }
	static Color yellow() { return Color(1.f,1.f,0.f,1.f); }
	static Color cyan()   { return Color(0.f,1.f,1.f,1.f); }
	static Color magenta(){ return Color(1.f,0.f,1.f,1.f); }
	static Color gray()   { return Color(.5f,.5f,.5f,1.f); }
	static Color orange() { return Color(1.f,.6f,.0f,1.f); }


	// ------------------------------------------------------------------------------------------------
	// Operators
	operator float *() { return &_r; }
};

}
#endif